import 'package:flutter/material.dart';
import 'package:flutter_sql/Provider.dart';
import 'package:flutter_sql/sql_util.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final provider = new Provider();
  await provider.init();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'F',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyPage(),
    );
  }
}

class MyPage extends StatefulWidget {
  @override
  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
  //创建对象，传入表名
  var sql = SqlUtil.setTable("user");

  Future<void> sss() async {
    String sql_insert =
        'INSERT INTO user(uid, phone, nickName) VALUES(?, ?, ?)';
    List list = [1, '123', 'aaa'];
    sql.rawInsert(sql_insert, list).then((id){
      setState(() {
        if (id > 0) {
          print("数据添加成功");
        } else {
          print("数据添加失败");
        }
      });
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // var sql = SqlUtil.setTable("user");
    // sss();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("test")),
      body: SingleChildScrollView(
        child: Column(
          children: [
            TextButton(
                onPressed: () {

                },
                child: Text("插入"))
          ],
        ),
      ),
    );
  }
}
